package com.share.order.controller;

import com.share.common.core.domain.R;
import com.share.common.core.web.controller.BaseController;
import com.share.common.core.web.domain.AjaxResult;
import com.share.common.core.web.page.TableDataInfo;
import com.share.common.security.annotation.InnerAuth;
import com.share.common.security.annotation.RequiresLogin;
import com.share.common.security.utils.SecurityUtils;
import com.share.order.domain.OrderInfo;
import com.share.order.service.OrderInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("orderInfo")
@Tag(name = "订单接口")
public class OrderInfoController extends BaseController {
    @Autowired
    private OrderInfoService orderInfoService;
    @Operation(summary = "获取未完成的订单")
    @RequiresLogin
    @GetMapping("getNoFinishOrder")
    public AjaxResult getNoFinishedOrder() {
        return success(orderInfoService.getNoFinishedOrder(SecurityUtils.getUserId()));
    }

    @Operation(summary = "获取未完成订单")
    @GetMapping("getNoFinishOrder/{userId}")
    public R<OrderInfo> getNoFinishOrder(@PathVariable Long userId) {
        return R.ok(orderInfoService.getNoFinishedOrder(userId));
    }
    @Operation(summary = "获取订单详细信息")
    @RequiresLogin
    @GetMapping(value = "/getOrderInfo/{id}")
    public AjaxResult getOrderInfo(@PathVariable("id") Long id)
    {
        return success(orderInfoService.selectOrderInfoById(id));
    }
    @Operation(summary = "获取用户订单分页列表")
    @RequiresLogin
    @GetMapping(value = "/userOrderInfo/{pageNum}/{pageSize}")
    public TableDataInfo userOrderInfo(@PathVariable("pageNum") Integer pageNum, @PathVariable("pageSize") Integer pageSize){
        startPage();
        return getDataTable(orderInfoService.userOrderInfo(SecurityUtils.getUserId(),pageNum,pageSize));
    }
    @Operation(summary = "根据订单号获取订单信息")
    @GetMapping("getByOrderNo/{orderNo}")
    public R<OrderInfo> getByOrderNo(@PathVariable String orderNo) {
        OrderInfo orderInfo = orderInfoService.getByOrderNo(orderNo);
        return R.ok(orderInfo);
    }

}
